package Model;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Scanner;
import java.util.StringTokenizer;
import View.optionGui;
import View.processing;

import classes.DocPair;

public class Comparison {
	public String [] data;
	public DocPair [] pairs;
	public static String path = "E:\\Documents";
	
	public Comparison(){
		data = null;
	}
	public String [] filesRead(String folder) throws IOException{
		File directory = new File(folder);
		if(!directory.exists()){
			return null;
		}
		File[] contents = directory.listFiles();
		BufferedReader[] rd = new BufferedReader[40];
		int count = 0;
		for(File f : contents)
		{
			rd[count] = new BufferedReader(new FileReader(f.getAbsolutePath()));
			count = count + 1;
		}
		data = new String[count];
		for(int i = 0; i < count;i++){
			String s = null;
			while( (s = rd[i].readLine()) != null){
				if(data[i] == null)
					data[i] = s +="\n";
				else
					data[i] += s += "\n";
			}
		}
		return this.data;
	}
	public int countWords(String path) throws FileNotFoundException{
		File f = new File(path);
		Scanner sc = new Scanner(new FileInputStream(f));
		int count=0;
		while(sc.hasNext()){
		    sc.next();
		    count++;
		}
		sc.close();
		return count;
	}
	public int countSimilarword(String path1, String path2) throws IOException{
		File f1 = new File(path1);
		File f2 = new File(path2);
		int count = 0;
		String data1 = new String();
		String data2 = new String();
		BufferedReader br = new BufferedReader(new FileReader(f1));
		BufferedReader br1 = new BufferedReader(new FileReader(f2));
		while( ((data1 = br.readLine()) != null) && ((data2 = br1.readLine()) != null) ){
			StringTokenizer st = new StringTokenizer(data1," ");
			StringTokenizer st1 = new StringTokenizer(data2," ");
			while(st.hasMoreTokens() && st1.hasMoreTokens()){
				String token1 = st.nextToken();
				String token2 = st1.nextToken();
				token1 = token1.toLowerCase();
				token2 = token2.toLowerCase();
				if(token1.equals(token2))
					count = count + 1;
			}
		}
		br.close();
		br1.close();
		return count;
	}
	public static void main(String[] args) throws IOException {
		processing processingGui = new processing();
		optionGui mainGui = new optionGui(processingGui);
		mainGui.setVisible();
		mainGui.register();	
	}
}
